package com.tbit.main.controller;

import com.tbit.common.entity.view.Result;
import com.tbit.main.util.DateTimeUtil;
import com.tbit.manager.api.OrderOAApi;
import com.tbit.manager.api.dto.OrderFunnelDTO;
import com.tbit.manager.api.dto.OrderStatReturnDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 运营分析-订单分析
 *
 * @author <a href="mailto:chen.wutian@tbit.com.cn">BUGTian</a>
 * @since 2025/2/27
 */
@Slf4j
@RestController
@RequestMapping("/operationsAnalysis/order")
public class OrderOAController {

    @Autowired
    private OrderOAApi orderOAApi;

    /**
     * 获取订单分析核心数据
     *
     * @author: mo.shanyong
     * @date: 2025/3/10 9:54
     * @param: accountId 区域ID
     * @param: startDate 开始时间
     * @param: endDate 结束时间
     * @return: com.tbit.uqbike.object.view.JsonResult
     */
    @GetMapping("/getOrderBaseData")
    public Result<Map<String, Object>> getOrderBaseData(Integer accountId, String startDate, String endDate) {
        log.info("getOrderBaseData---------->startDate:{},endTime:{}", startDate, endDate);
        Map<String, Object> orderBaseData = orderOAApi.getOrderBaseData(accountId, startDate, endDate);
        return Result.success(orderBaseData);
    }

    /**
     * 获取订单收益折线图数据
     *
     * @author: mo.shanyong
     * @date: 2025/3/10 9:57
     * @param: accountId 区域Id
     * @param: startDate 开始时间
     * @param: endDate 结束时间
     * @return: com.tbit.uqbike.object.view.JsonResult
     */
    @GetMapping("/getOrderFeeLineData")
    public Result<List<OrderStatReturnDTO>> getOrderFeeLineData(Integer accountId, String startDate, String endDate) {
        log.info("getOrderFeeLineData----->startDate:{},endTime:{}", startDate, endDate);
        List<OrderStatReturnDTO> orderFeeLineData = orderOAApi.getOrderFeeLineData(accountId, startDate, endDate);
        return Result.success(orderFeeLineData);
    }

    /**
     * 订单量折线图数据
     *
     * @author: mo.shanyong
     * @date: 2025/3/10 9:57
     * @param: accountId 区域id
     * @param: startDate 开始时间
     * @param: endDate 结束时间
     * @return: com.tbit.uqbike.object.view.JsonResult
     */
    @GetMapping("/getOrderNumLineData")
    public Result<List<OrderStatReturnDTO>> getOrderNumLineData(Integer accountId, String startDate, String endDate) {
        log.info("getOrderNumLineData---------->startDate:{},endTime:{}", startDate, endDate);
        List<OrderStatReturnDTO> orderNumLineData = orderOAApi.getOrderNumLineData(accountId, startDate, endDate);
        return Result.success(orderNumLineData);
    }

    /**
     * 车均收益折线图数据
     *
     * @author: mo.shanyong
     * @date: 2025/3/13 14:57
     * @param: accountId 区域id
     * @param: startDate 开始时间
     * @param: endDate 结束时间
     * @return: com.tbit.common.entity.view.Result<java.util.List < com.tbit.manager.api.dto.OrderStatReturn>>
     */
    @GetMapping("/getMachineAvgFeeLineData")
    public Result<List<OrderStatReturnDTO>> getMachineAvgFeeLineData(Integer accountId, String startDate, String endDate) {
        log.info("getMachineAvgFeeLineData---------->startDate:{},endTime:{}", startDate, endDate);
        List<OrderStatReturnDTO> machineAvgFeeLineData = orderOAApi.getMachineAvgFeeLineData(accountId, startDate, endDate);
        return Result.success(machineAvgFeeLineData);
    }

    /**
     * 车均单量折线图数据
     *
     * @author: mo.shanyong
     * @date: 2025/3/10 10:01
     * @param: accountId 区域id
     * @param: startDate 开始时间
     * @param: endDate 结束时间
     * @return: com.tbit.uqbike.object.view.JsonResult
     */
    @GetMapping("/getMachineAvgOrderLineData")
    public Result<List<OrderStatReturnDTO>> getMachineAvgOrderLineData(Integer accountId, String startDate, String endDate) {
        log.info("getMachineAvgOrderLineData--------->startDate:{},endTime:{}", startDate, endDate);
        List<OrderStatReturnDTO> machineAvgOrderLineData = orderOAApi.getMachineAvgOrderLineData(accountId, startDate, endDate);
        return Result.success(machineAvgOrderLineData);
    }

    /**
     * 正常、站外、超区订单折线图
     *
     * @author: mo.shanyong
     * @date: 2025/3/10 10:03
     * @param: accountId 区域id
     * @param: startDate 开始时间
     * @param: endDate 结束时间
     * @return: com.tbit.uqbike.object.view.JsonResult
     */
    @GetMapping("/getOrderFinishTypeData")
    public Result<List<OrderStatReturnDTO>> getOrderFinishTypeData(Integer accountId, String startDate, String endDate) {
        log.info("getOrderFinishTypeData---------->startDate:{},endTime:{}", startDate, endDate);
        List<OrderStatReturnDTO> orderFinishTypeData = orderOAApi.getOrderFinishTypeData(accountId, startDate, endDate);
        return Result.success(orderFinishTypeData);
    }

    /**
     * 车辆里程柱状图数据
     *
     * @author: mo.shanyong
     * @date: 2025/3/10 10:04
     * @param: accountId 区域id
     * @param: startDate 开始时间
     * @param: endDate 结束时间
     * @return: com.tbit.uqbike.object.view.JsonResult
     */
    @GetMapping("/getOrderMileagePieData")
    public Result<List<OrderStatReturnDTO>> getOrderMileagePieData(Integer accountId, String startDate, String endDate) {
        log.info("getOrderMileagePieData------------>startDate:{},endTime:{}", startDate, endDate);
        List<OrderStatReturnDTO> orderMileagePieData = orderOAApi.getOrderMileagePieData(accountId, startDate, endDate);
        return Result.success(orderMileagePieData);
    }

    /**
     * 获取订单支付方式饼图数据
     *
     * @author: mo.shanyong
     * @date: 2025/3/10 10:06
     * @param: accountId 区域id
     * @param: startDate 开始时间
     * @param: endDate 结束时间
     * @return: com.tbit.uqbike.object.view.JsonResult
     */
    @GetMapping("/getOrderPayTypePieData")
    public Result<List<OrderStatReturnDTO>> getOrderPayTypePieData(Integer accountId, String startDate, String endDate) {
        log.info("getOrderPayTypePieData---------->startDate:{},endTime:{}", startDate, endDate);
        List<OrderStatReturnDTO> orderPayTypePieData = orderOAApi.getOrderPayTypePieData(accountId, startDate, endDate);
        return Result.success(orderPayTypePieData);
    }

    /**
     * @description: 获取时间段内区域的订单的骑行时长的分布数据
     * @author: mo.shanyong
     * @date: 2025/3/14 9:11
     * @param: accountId 区域id
     * @param: startDate 开始时间 2025-03-01 00:00:00
     * @param: endDate 结束时间 2025-03-01 23:59:59
     * @return: java.util.List<com.tbit.uqbike.object.pojo.dto.OrderMileageDTO>
     */
    @GetMapping("/getOrderTimeDistribution")
    public Result<List<OrderStatReturnDTO>> getOrderTimeDistribution(Integer accountId, String startDate, String endDate) {

        log.info("getOrderTimeDistribution------>startDate:{},endTime:{}", startDate, endDate);
        List<OrderStatReturnDTO> orderTimeDistribution = orderOAApi.getOrderTimeDistribution(accountId, startDate, endDate);
        return Result.success(orderTimeDistribution);
    }
    /**
     * @description: 获取订单转化数据
     * @author: mo.shanyong
     * @date: 2025/4/17 11:21
     * @param: accountId 区域id
     * @param: startDate 筛选开始时间 2025-03-01 00:00:00
     * @param: endDate  筛选结束时间 2025-03-01 23:59:59
     * @return: com.tbit.manager.api.dto.OrderFunnelDTO
     */
    @GetMapping("/orderAnalysisFunnel")
    public Result<OrderFunnelDTO> orderAnalysisFunnel(Integer accountId, String startDate, String endDate){
        log.info("orderAnalysisFunnel------>accountId:{},startDate:{},endTime:{}", accountId,startDate, endDate);
        OrderFunnelDTO orderFunnelDTO = orderOAApi.orderAnalysisFunnel(accountId, startDate, endDate);
        return Result.success(orderFunnelDTO);
    }
}
